package com.gxc.tree;

/**
 * 二叉树每个结点都有一个int型权值，给定一棵二叉树，要求计算出从根结点到叶结点的所有路径中，权值和最大的值为多少。
 * 权值和：从跟节点到叶节点的value的总和
 *
 */
public class WeightSum {

    public Info treeWeight(TreeBean treeBean) {
        if (treeBean == null) return new Info(0);

        Info leftInfo = treeWeight(treeBean.left);
        Info rightInfo = treeWeight(treeBean.right);

        int weight = Math.max(leftInfo.maxWeight, rightInfo.maxWeight) + treeBean.value;
        return new Info(weight);
    }

    public class Info {

        public int maxWeight;

        public Info(int maxWeight) {
            this.maxWeight = maxWeight;
        }
    }


}
